<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>list</title>
</head>
<body>
<script>
    function printFibonacci(n) {
        if (n <= 0) {
            console.log("请输入一个正整数。");
            return;
        }
        if (n === 1) {
            console.log("斐波那契数列第 1 项: 0");
            return;
        }
        let a = 0, b = 1;
        console.log("斐波那契数列第 1 项: " + a);

        for (let i = 2; i <= n; i++) {
            let temp = a + b;
            console.log("斐波那契数列第 " + i + " 项: " + b);
            a = b;
            b = temp;
        }
    }
    printFibonacci(20);
</script>
</body>
</html>
